How to make if else Condition in Adv. SQL Query? 您所在的位置:网站首页 homezipcode 纽约 How to make if else Condition in Adv. SQL Query?

How to make if else Condition in Adv. SQL Query?

2024-03-28 03:22| 来源: 网络整理| 查看: 265

Hello Roshan,

The CASE condition would be a good choice for your requirement. Regarding your note, you don't have to worry about data types if your HomeZipCode output structure has an attribute of type Text - if you try to store an Integer in it, it will be implicitly converted to a string.

I don't know what error you're receiving, but I suspect the issue is that a CASE can only return one datatype (or multiple datatypes if they can be implicitly converted). So this will return an error, because it will return a string or an integer:

SELECT CASE WHEN 0 = 0 THEN 'Hello' ELSE 1 END as HomeZipCode

but this will not, since it only returns strings:

SELECT CASE WHEN 0 = 0 THEN 'Hello' ELSE '1' END as HomeZipCode

All you need to do is convert or cast your HomeZipCode into a String in the CASE branch, something like this:

CASE WHEN {Customers}.[HomeZipCode]=0 THEN 'Hello' ELSE CONVERT(varchar, {Customers}.[HomeZipCode]) END as HomeZipCode

and since your CASE now only returns strings, you shouldn't receive any errors.



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有